package 简单多状态;

import java.util.Scanner;

public class test2 {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int[] nums = new int[n];
        for (int i = 0; i < n; i++) {
            nums[i] = in.nextInt();
        }
        System.out.println(rob(nums));
    }

    public static int rob(int[] nums) {
        int n = nums.length;
        // 直接分为两种情况,一种取第一个,一种不取第一个
        return Math.max(nums[0]+getResult(nums,2,n-2),getResult(nums,1,n-1));
    }

    public static int getResult(int[] nums,int left,int right){
        int n = nums.length;
        if(left>right)
            return 0;
        int[] dp1 = new int[n];
        int[] dp2 = new int[n];
        dp1[left] = nums[left];
        for (int i = left+1; i <= right; i++) {
            dp1[i] = dp2[i-1]+nums[i];
            dp2[i] = Math.max(dp1[i-1],dp2[i-1]);
        }
        return Math.max(dp1[right],dp2[right]);
    }
}
